/*~~~~~~~~~~~~~~~~~~~~~~
[Bot IRC]
Auteur: Thaeron
Projet: NewSyndrome
Version: 1.5.2
Licence: GPL

Copyright (C) 2004 - 2007 Thaeron

This program is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License as 
published by the Free Software Foundation; either version 2 of the 
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
General Public License for more details.

You should have received a copy of the GNU General Public License 
along with this program; if not, write to the Free Software 
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 
USA
~~~~~~~~~~~~~~~~~~~~~~*/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

#define byte char
#define bot_add_timeout_int_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,sizeof(int))
#define bot_add_timeout_str_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,strlen(z)+1)
#define bot_add_timeout_char_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,1)
#define bot_add_timeout_byte_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,1)

enum
{ CLEAN, UNLOAD, LOAD, UNLINK, UPDATE, REHASH, REINIT };

enum
{ LOAD_OK, NO_MODULE, NO_IDENT, ALREADY_LOAD, UNLOAD_OK, ALREADY_UNLOAD, NO_CMD };

enum
{ BAD, GOOD };

enum
{ REMOVE_TIMEOUT, KEEP_TIMEOUT };

typedef struct _conf conf;
struct _conf
{
  char *filename;
  char *nick;
  char *rn;
  char *ident;
  char *server;
  char *myip;
  char *root_path;
  char *bdd_path;
  char *charset_from;
  char *charset_to;
  char *nickserv_pass;
  char *server_pass;
  char *module_path;
  int port;
  int nbchan;
  char **channel;
  char car_cmd;
  byte af_default;
  int af_delay;
  int reco_delay;
};

typedef struct _msg msg;
struct _msg
{
  char **argu;
  int nbarg;
  char *sender;
  char *sender_nick;
  char *sender_ident;
  char *sender_host;
  char *cmd;
  char *dest;
  char *raw_txt;
};

typedef struct _identity identity;
struct _identity
{
  char *nick;
  char *ident;
  char *host;
};

typedef struct _module_list module_list;
struct _module_list
{
  char *name;
  char *ident;
  char *description;
  char *auteur;
  char *version;
  module_list *next;
};

#ifdef WIN32
#include <windows.h>
#define delay(x) Sleep(x)
#include "share_func.c"

#else
#define delay(x) usleep(x * 1000)
#define closesocket(x) close(x)

#ifdef __cplusplus
extern "C" {
#endif

void log_module_info (char *merr);
void log_module_infof (char *s, ...);
void clean_txt (char *txt);
int cmpstar (char *ref, char *star);
char *strf (char *s, ...);
char *argu_to_string (char **argu, int nbarg, char *radical, int depart);
int identify_mask (identity * i, char *m);
void free_identity (identity *a);
char *str_replace (char *data, char *old_str, char *new_str);
char *str_suppr (char *buffer, char *del);
char *multi_str_replace (char *data, ...);
char *multi_str_suppr (char *data, ...);

void bot_set_ident_module (char *n);
void bot_set_auteur_module (char *n);
void bot_set_desc_module (char *n);
void bot_set_version_module (char *n);
void bot_send_privmsg (char *dest, char *str);
void bot_send_notice (char *dest, char *str);
void bot_send_raw (char *str);
void bot_send_privmsgf (char *dest, char *s, ...);
void bot_send_noticef (char *dest, char *s, ...);
void bot_send_rawf (char *s, ...);
void bot_add_cmd_handler (char *n, char *fct);
int bot_rm_cmd_handler (char *n);
void bot_add_type_handler (char *n, char *fct);
int bot_rm_type_handler (char *n);
void bot_add_timeout_handler (int t, char *fct);
void bot_add_timeout_with_param_handler (int t, char *fct, void *param_p, unsigned int size_p);
void bot_unprotect_time_module (void);
void bot_protect_time_module (void);

int bot_unload_module (char *n);
int bot_load_module (char *n);
int bot_load_module_cmd (char *cmd);
int bot_unload_module_cmd (char *cmd);
void bot_actualise_ping (void);
unsigned int bot_get_time_up (void);
char *bot_get_kernel_version (void);
void module_loader_add_link (char *n, void *ad);
void module_loader_rm_link (char *n);
conf *bot_conf_get_addr (void);
module_list *bot_get_module_list (void);
void bot_free_module_list (module_list * ml);
char *bot_get_info_from_conf (char *base, unsigned int occur);

char **bot_get_userlist (char *chan);
char **bot_get_chanlist (char *user);
char *bot_get_mask (char *user);

int is_botnick (char *n);

#ifdef __cplusplus
}
#endif

#endif
